<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Recombine Tags And Decorations</title>
<script src="extractSourceSpans.js"></script>
<script src="numberLines.js"></script>
<script src="recombineTagsAndDecorations.js"></script>
<script src="http://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script>
<link rel="stylesheet" href="../src/prettify.css" type="text/css" />
<style>
.ok { background: #dfd }
.error, .failure { background: #fdd }
.error { white-space: pre }
td { font-family: monospace }
tr { vertical-align: top }
</style>
</head>

<body>
<h1>Recombine Tags And Decorations</h1>

<table border="1" cellpadding="2" cellspacing="0">
  <tr><th colspan="4">Test Single Decoration</th></tr>
  <tr>
    <td><code class="testinput">"Hello, World!"</code></td>
    <td class="decorations">[0, 'str']</td>
    <td><code><span class="str">"Hello, World!"</span></code></td>
  </tr>
  <tr><th colspan="4">Test Single Span</th></tr>
  <tr>
    <td><code class="testinput">print "Hello, &lt;World&gt;!";</code></td>
    <td class="decorations">[0, 'kwd', 5, 'pln', 6, 'str', 14, 'tag', 21, 'str', 23, 'pun']</td>
    <td><code><span class="kwd">print</span><span class="pln"> </span><span class="str">"Hello, </span><span class="tag">&lt;World&gt;</span><span class="str">!"</span><span class="pun">;</span></code></td>
  </tr>
  <tr><th colspan="4">Test Interleaved</th></tr>
  <tr>
    <td><code class="testinput">print "Hello, &lt;<b>World</b>&gt;!";</code></td>
    <td class="decorations">[0, 'kwd', 5, 'pln', 6, 'str', 14, 'tag', 21, 'str', 23, 'pun']</td>
    <td><code><span class="kwd">print</span><span class="pln"> </span><span class="str">"Hello, </span><span class="tag">&lt;</span><b><span class="tag">World</span></b><span class="tag">&gt;</span><span class="str">!"</span><span class="pun">;</span></code></td>
  </tr>
</table>

<script>
if (!document.body.getElementsByClassName) {
  document.body.getElementsByClassName = function (className) {
    className = className.replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, ' ');
    var results = [];
    function walk(node) {
      if (node.nodeType !== 1) { return; }
      // This test should be order-insensitive.
      if ((' ' + node.className + ' ').indexOf(className) >= 0) {
        results[results.length] = node;
      }
      for (var child = node.firstChild; child; child = child.nextSibling) {
        walk(child);
      }
    }
    walk(document.body);
    return results;
  };
}

setTimeout(function () {
  var testInputs = Array.prototype.slice.call(
     document.body.getElementsByClassName('testinput'), 0);
  for (var i = 0, n = testInputs.length; i < n; ++i) {
    var testInput = testInputs[i];
    var decorationsNode = testInput.parentNode.nextSibling;
    while (decorationsNode.nodeType !== 1) { decorationsNode = decorationsNode.nextSibling; }
    var testResult = decorationsNode.nextSibling;
    while (testResult.nodeType !== 1) { testResult = testResult.nextSibling; }
    var actual = document.createElement('TD');
    testResult.parentNode.appendChild(actual);
    var clone = testInput.cloneNode(true);
    clone.className = '';  // IE
    clone.removeAttribute('class');  // Not IE.
    actual.appendChild(clone);
    var job = extractSourceSpans(clone);
    job.decorations = eval(decorationsNode.innerText || decorationsNode.textContent);
    try {
      recombineTagsAndDecorations(job);
      var passed = testResult.innerHTML === actual.innerHTML;
      if (!passed) {
        console.log(JSON.stringify(testResult.innerHTML) + ' !==\n' + JSON.stringify(actual.innerHTML));
      }
      actual.className = passed ? 'ok' : 'failure';
    } catch (ex) {
      actual.className = 'error';
      actual.appendChild(document.createTextNode(
          'Error: ' + (ex.message || ex)  + '\n' + ex.stack));
    }
    actual.className += ' actual';
  }
}, 0)</script>

<hr>
<address></address>
<!-- hhmts start --> Last modified: Tue Mar 29 10:41:34 PDT 2011 <!-- hhmts end -->
</body> </html>
